package com.cloud.autoconfigure;

import com.cloud.async.business.core.BaseAsyncResultHandler;
import com.cloud.async.error.ErrorHandler;
import com.cloud.async.error.impl.DefaultErrorHandler;
import com.cloud.async.monitor.ResultHandlerMonitor;
import com.cloud.async.monitor.impl.DefaultResultHandlerMonitor;
import com.cloud.async.result.core.handler.StandardAsyncResultHandler;
import com.cloud.async.retry.DefaultRetryPolicy;
import com.cloud.async.retry.RetryPolicy;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * @author chengr
 */
@Component
@EnableConfigurationProperties(WebAsyncAutoBean.class)
@ConfigurationProperties(prefix = "web.cloud.async")
public class WebAsyncAutoBean {

    /**
     * 自动配置全局等待时间默认1s
     */
    private Long globalTimeout = 1000L;

    /**
     * 标准Map类型数据长度
     */
    private Integer dataCapacity = 1024;

    /**
     * 调用任务失败重试次数 默认1
     */
    private Integer retryCount = 1;

    /**
     * 结果解析
     */
    private Class<? extends BaseAsyncResultHandler> resultHandler = StandardAsyncResultHandler.class;

    /**
     * 用于处理异步任务执行过程中的异常，允许调用方自定义错误返回逻辑。
     */
    private Class<? extends ErrorHandler> errorHandler = DefaultErrorHandler.class;

    /**
     * 用于监控异步任务的生命周期（如任务开始、完成、失败等）
     */
    private Class<? extends ResultHandlerMonitor> resultHandlerMonitor = DefaultResultHandlerMonitor.class;


    Class<? extends RetryPolicy> retryPolicy = DefaultRetryPolicy.class;

    public void setRetryPolicy(Class<? extends RetryPolicy> retryPolicy) {
        this.retryPolicy = retryPolicy;
    }

    public Class<? extends RetryPolicy> getRetryPolicy() {
        return retryPolicy;
    }

    public Class<? extends BaseAsyncResultHandler> getResultHandler() {
        return resultHandler;
    }

    public void setResultHandler(Class<? extends BaseAsyncResultHandler> resultHandler) {
        this.resultHandler = resultHandler;
    }


    public void setErrorHandler(Class<? extends ErrorHandler> errorHandler) {
        this.errorHandler = errorHandler;
    }

    public Class<? extends ErrorHandler> getErrorHandler() {
        return errorHandler;
    }

    public void setResultHandlerMonitor(Class<? extends ResultHandlerMonitor> resultHandlerMonitor) {
        this.resultHandlerMonitor = resultHandlerMonitor;
    }

    public Class<? extends ResultHandlerMonitor> getResultHandlerMonitor() {
        return resultHandlerMonitor;
    }

    public Integer getRetryCount() {
        return retryCount;
    }

    public void setRetryCount(Integer retryCount) {
        this.retryCount = retryCount;
    }

    public Long getGlobalTimeout() {
        return globalTimeout;
    }

    public void setGlobalTimeout(Long globalTimeout) {
        this.globalTimeout = globalTimeout;
    }

    public Integer getDataCapacity() {
        return dataCapacity;
    }

    public void setDataCapacity(Integer dataCapacity) {
        this.dataCapacity = dataCapacity;
    }

    public WebAsyncAutoBean() {
    }
}
